package cn.tedu.demo;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.io.PipedWriter;
import java.io.PrintWriter;

@Component
@Lazy
public class FileLogger {
    public PrintWriter out;

    @PostConstruct
    public void open() throws IOException {
        out = new PrintWriter("Demo.txt");
        System.out.println("打开文件Demo.txt");
    }

    @PreDestroy
    public void close() {
        out.close();
        System.out.println("关闭了文件Demo.txt");
    }
}
